package com.zzjson.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2020 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson.socket</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2020年02月14日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class ClientSocketDemo {
	public static void main(String[] args) {

		try {
			Socket socket = new Socket("127.0.0.1", 8080);
			//写出去
			PrintWriter out = new PrintWriter(socket.getOutputStream(), true);

			//输入流
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

			//控制台的输入流
			BufferedReader sin = new BufferedReader(new InputStreamReader(System.in));

			//控制台的输入
			String line = sin.readLine();
			while (!"bye".equals(line)) {

				out.println(line);

				System.out.println("server:" + bufferedReader.readLine());
				line = sin.readLine();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
